package com.stool.cloud.service.impl;

import com.google.common.collect.Lists;
import com.stool.cloud.dao.AccountDao;
import com.stool.cloud.service.IAccountService;
import io.seata.spring.annotation.GlobalTransactional;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * @author Felix YF Dong
 * @Description
 * @Date 2023/2/14
 */
@Slf4j
@Service
public class AccountServiceImpl implements IAccountService {

    @Resource
    private AccountDao accountDao;

    /**
     * 扣减账户余额
     */
    @Override
    public void decrease(Long userId, BigDecimal money) {
        log.info("------->account-service中扣减账户余额开始");
        //模拟超时异常，全局事务回滚
//        try {
//            TimeUnit.SECONDS.sleep(20);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
        int a= 1/0;

        accountDao.decrease(userId, money);
        log.info("------->account-service中扣减账户余额结束");
    }
}
